package com.roc.steelend.controller;


import com.auth0.jwt.interfaces.DecodedJWT;
import com.roc.steelend.controller.vo.common.BuyByRecoding;
import com.roc.steelend.controller.vo.common.SaleByRecoding;
import com.roc.steelend.controller.vo.returnformat.ReturnMsg;
import com.roc.steelend.controller.vo.returnformat.ReturnMsgForTable;
import com.roc.steelend.controller.vo.sale.JuanBanSaleOrderVo;
import com.roc.steelend.controller.vo.sale.OtherProductsSaleOrderVo;
import com.roc.steelend.controller.vo.sale.PingBanSaleOrderVo;
import com.roc.steelend.service.SaleOrderService;
import com.roc.steelend.util.JWTUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin
@Api(tags = "销售订单功能接口")
public class SaleOrderController {

    @Autowired
    private SaleOrderService saleOrderService;

    @PostMapping("/v1/sale/pingban")
    @ApiOperation(value = "销售平板提交接口",notes = "需要一个具体的所有信息类")
    public ReturnMsg salePingBan(@RequestBody PingBanSaleOrderVo pingBanSaleOrderVo, HttpServletRequest request){
        System.out.println(pingBanSaleOrderVo);
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();
        return saleOrderService.addSalePingBanOrderService(pingBanSaleOrderVo,Integer.valueOf(employeeIdAsString));
    }

    @PostMapping("/v1/sale/juanban")
    @ApiOperation(value = "销售卷板提交接口",notes = "需要一个具体的所有信息类")
    public ReturnMsg saleJuanBan(@RequestBody JuanBanSaleOrderVo juanBanSaleOrderVo,HttpServletRequest request){
        System.out.println(juanBanSaleOrderVo);
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();
        return saleOrderService.addSaleJuanBanOrderService(juanBanSaleOrderVo,Integer.valueOf(employeeIdAsString));
    }

    @PostMapping("/v1/sale/otherproducts")
    @ApiOperation(value = "销售其他类型产品提交接口",notes = "需要一个具体的所有信息类")
    public ReturnMsg saleOtherProducts(@RequestBody OtherProductsSaleOrderVo otherProductsSaleOrderVo, HttpServletRequest request){
        System.out.println(otherProductsSaleOrderVo);
        String token = request.getHeader("token");
        DecodedJWT decodedJWT = JWTUtil.getToken(token);
        String employeeIdAsString = decodedJWT.getClaim("employeeId").asString();
        return saleOrderService.addSaleOtherProductsOrderService(otherProductsSaleOrderVo,Integer.valueOf(employeeIdAsString));
    }

    //
    @PostMapping("/v1/sale/find/recording")
    @ApiOperation(value = "销售查询接口(ps:特殊情况使用post,但不修改数据!!!)",notes = "可选择性填一个所有信息查询器的类(ps:特殊情况使用post,但不修改数据!!!)")
    private ReturnMsgForTable saleFindRecoding(@RequestBody(required = false)@ApiParam(value = "条件选择器类",required = false) SaleByRecoding selectMsg){
        ReturnMsgForTable returnMsgForTable = new ReturnMsgForTable();
        returnMsgForTable.setCurrenPage(selectMsg.getCurrentPage());
        returnMsgForTable.setObjectList( saleOrderService.saleFindRecoding(selectMsg));
        returnMsgForTable.setTotal(saleOrderService.saleFindRecodingCount(selectMsg));
        return returnMsgForTable;
    }




}
